Fixed some flashing issues on STM32L0 #1330
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
While trying to use st-link to flash a STM32L051 on a custom board, the flash loader fails in
stm32l1_write_half_pages
, and the fallback path usually reports "Flash memory contains a non-erased value" (but still successfully writes the flash since the NOTZEROERR doesn't prevent the write on this category 3 device - 3.3.4 RM0377). Sost-flash write
does write the flash but reports failure, andload
in gdb usingst-util
server reportsError finishing flash operation
.I found two issues in the flashing code:
stm32l1_write_half_pages
callsstlink_flash_loader_run
with a localflash_loader_t
struct that is never initialized, so the loader is run using uninitialized values for the loader code base address and the SRAM buffer addressloader_code_stm32lx
is used for both STM32L0 devices with armv6-m cores and STM32L1 devices with armv7-m, but it usesadd
instructions that are only supported in armv7-m, so when loader code runs it writes one word to flash and then faults on theadd
.With these issues fixed, flashing works without error on this device.
This is related to the various reported issues about failures flashing STM32Lx devices (e.g. in #681) and probably helps fix some of those, but I don't have other hardware to test on to confirm if this improves things on devices other than STM32L051. Based on the code history these 2 bugs seem to be introduced more recently than some of the early reported issues, so there may be some remaining issues too.
It seems like the current flashloader implementation in
stm32l1_write_half_pages
maybe doesn't have much advantage over the fallback path usingstlink_write_mem32
since both wait for flash programming to complete from the host system every halfpage, but these 2 commits make this path work for now on in my testing on STM32L051( in the future it can potentially be enhanced to poll on
FLASH_SR_BSY
every halfpage from the device instead of the host or removed if not useful)(Closes #681) (Closes #1203) (Closes #1225) (Closes #1253) (Closes #1289)